
# hive_app/models.py
from django.db import models
from django.utils import timezone


class User(models.Model):
    USER_TYPE_CHOICES = (
        (1, '管理员'),
        (2, '普通用户'),
    )

    username = models.CharField(max_length=255, unique=True)
    password = models.CharField(max_length=255)
    createTime = models.DateField(default=timezone.now)
    user_type = models.IntegerField(choices=USER_TYPE_CHOICES, default=2)

    class Meta:
        db_table = 'user'
        verbose_name = '用户'
        verbose_name_plural = '用户管理'

    def __str__(self):
        return f"{self.username} ({self.get_user_type_display()})"

    def is_admin(self):
        return self.user_type == 1


class History(models.Model):
    id = models.AutoField("id",primary_key=True)
    movieId = models.CharField("电影ID",max_length=255,default='')
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    count = models.IntegerField('收藏次数',default=1)

    class Meta:
        db_table = "history"


